
import * as THREE from 'three';
import ControllerState from '../ControllerState';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { TransformControls } from 'three/examples/jsm/controls/TransformControls';

export default async function createThree(s: ControllerState, cont: HTMLDivElement | null | undefined) {
    if (!cont) return;
    s.cont = cont;

    //创建场景 -----------------------------------------------------------------------------------------------
    s.scene = new THREE.Scene();
    s.scene.background = new THREE.Color(0x444444);

    //创建摄像机 -----------------------------------------------------------------------------------------------
    s.camera = new THREE.PerspectiveCamera(75, cont.offsetWidth / cont.offsetHeight, 0.1, 1000);
    s.camera.position.set(10, 10, 10);

    //创建渲染器  
    cont.innerHTML = "";
    s.renderer = new THREE.WebGLRenderer({ antialias: true });
    s.renderer.setClearColor(new THREE.Color(0xffffff));
    s.renderer.setSize(cont.offsetWidth, cont.offsetHeight);
    s.renderer.shadowMap.enabled = true;
    s.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
    cont.appendChild(s.renderer.domElement);

    //摄像机轨道管理
    s.controls = new OrbitControls(s.camera, s.renderer.domElement);
    s.controls.enabled = false;

    //原件控制器
    s.transformControls = new TransformControls(s.camera, s.renderer.domElement);
}

